#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
    Base类
        初始化方法
        查找元素的方法
        点击元素的方法
        输入方法
        获取文本的方法
        截图方法
"""
import time

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from base import BaseUrl


class Driver:
    """webdriver的实例属性工具类"""
    driver = webdriver.Chrome()
    # 浏览器最大化
    driver.maximize_window()
    driver.get(BaseUrl.deepbluesaas_login_url)


class Base(Driver):
    def __init__(self, url):
        """初始化url"""
        self.url = url

    def get_url(self):
        """访问页面网址，谁需要谁传"""
        self.driver.get(self.url)

    # 查找元素
    def base_find_element(self, loc, timeout=10, poll=0.5):
        return WebDriverWait(self.driver, timeout=timeout, poll_frequency=poll).until(lambda x: x.find_element(*loc))

    def base_click(self, loc):
        self.base_find_element(loc).click()

    def base_input(self, loc, value):
        ele = self.base_find_element(loc)
        ele.clear()
        ele.send_keys(value)

    def base_get_text(self, loc):
        self.base_find_element(loc).text()

    def base_get_img(self):
        self.driver.get_screenshot_as_file("../image/error.png")
